//
//  IManager+RequestServerDetailInfo.m
//  RocketProject
//
//  Created by chen jiedan on 13-10-2.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "IManager+RequestServerDetailInfo.h"
#import "CommonDefines.h"
#import "NSString+NSString_Ex_.h"
#import "NetUrlDefines.h"
#import "RequestUtlity.h"
#import "FrameworkRelativeDefines.h"
#import "GloableEngineService.h"
#import "RCBaseServerDataModel.h"
#import "RCOderDetailModel.h"
#import "TravelException.h"
#import "RCActivityDetailInfoModel.h"

@implementation IManager (RequestServerDetailInfo)


-(int64_t)requestOrderDetailInfo:(NSString *)orderID withIsOrder:(BOOL)isRealOrder  withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:orderID]) {
        return kInvalidRequestId;
    }
    NSString *shopBduss = [[GloableEngineService sharedInstance] shopBduss];

    NSString *urlSuffix = nil;
    if (isRealOrder) {
        urlSuffix =  [NSString stringWithFormat:kRCOrderDetailInfoPrefix,shopBduss,orderID];
    }else{
        urlSuffix =  [NSString stringWithFormat:kRCActivityOrderInfoDetailInfoPrefix,shopBduss,orderID];
    }
    
    
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    KFLog(@"request url %@",url);
    //    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObject:@"MerchantDetailJson"] forKeys:[NSArray arrayWithObject:@"FakeJson"]];
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCOderDetailModel class]
                                                     withDataDelegate:delegate];
    
}


-(int64_t)requestDelOrderDetailInfo:(NSString *)orderID withDelegate:(id<IManagerDelegate>)delegate  withIsOrder:(BOOL)isRealOrder

{
    if ([NSString stringIsNullOrEmpty:orderID]) {
        return kInvalidRequestId;
    }
    NSString *shopBduss = [[GloableEngineService sharedInstance] shopBduss];
    NSString *shopID = [[GloableEngineService sharedInstance] shopID];
    
    NSString *urlSuffix = nil;
    if (isRealOrder) {
        urlSuffix = [NSString stringWithFormat:kRCOrderDelPrefix,shopBduss,shopID,orderID];
    }else{
        urlSuffix = [NSString stringWithFormat:kRCActivityAttendDelPrefix,shopBduss,orderID];
    }
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    KFLog(@"request url %@",url);
    //    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObject:@"MerchantDetailJson"] forKeys:[NSArray arrayWithObject:@"FakeJson"]];
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCBaseServerDataModel class]
                                                     withDataDelegate:delegate];
}

-(int64_t)requestPostOrderInfo:(NSString *)orderID
                   withIsOrder:(BOOL)isRealOrder
                      withUser:(NSString *)userName
                     withPhone:(NSString *)userPhone
                   withContent:(NSString *)content
                  withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:content] && [NSString stringIsNullOrEmpty:userPhone]) {
        return kInvalidRequestId;
    }
    if (nil == userName) {
        userName = @"";
    }
    NSString *shopBduss = [[GloableEngineService sharedInstance] shopBduss];
    
    NSMutableDictionary *postValue = [NSMutableDictionary dictionary];
    [postValue setObject:shopBduss forKey:@"shopbduss" withDefaultValue:@""];
    if (isRealOrder) {
        [postValue setObject:orderID forKey:@"orderid" withDefaultValue:@""];
    }else{
        [postValue setObject:orderID forKey:@"dataid" withDefaultValue:@""];
    }
    [postValue setObject:userName  forKey:@"name" withDefaultValue:@""];
    [postValue setObject:userPhone forKey:@"phone" withDefaultValue:@""];
    [postValue setObject:content forKey:@"content" withDefaultValue:@""];

//    [postValue setObject:[GloableEngineService sharedInstance].nickName forKey:@"name" withDefaultValue:@""];
//    [postValue setObject:[GloableEngineService sharedInstance].bduss forKey:@"bduss" withDefaultValue:@""];
    // 异步获取数据
    NSString *urlSuffix = nil;
    if (isRealOrder) {
        urlSuffix = kRCOrderNoticePrefix;
    }else{
        urlSuffix = kRCActivityNoticePrefix;
    }
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    
    KFLog(@"request url %@",url);
    return [[IDataProvider sharedInstance] asyncPostData:url postValues:postValue postDataList:nil userInfo:nil withDataParseClass:[RCBaseServerDataModel class] withDataDelegate:delegate];
}

-(int64_t)requestPostOrderInfo:(NSString *)orderID
                   withEventID:(NSString *)eventID
                   withIsOrder:(BOOL)isRealOrder
                    withStatus:(NSInteger)status
                withChargeType:(NSString *)chargeType
                     withPrice:(NSString *)price
                   withContent:(NSString *)content
                  withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:orderID] ) {
        return kInvalidRequestId;
    }
    if (nil == price) {
        price = @"";
    }
    if (nil == content) {
        content = @"";
    }
   
    
    NSString *shopBduss = [[GloableEngineService sharedInstance] shopBduss];
    
    NSMutableDictionary *postValue = [NSMutableDictionary dictionary];
    [postValue setObject:shopBduss forKey:@"shopbduss" withDefaultValue:@""];
    if (isRealOrder) {
        [postValue setObject:orderID forKey:@"orderid" withDefaultValue:@""];
        [postValue setObject:content forKey:@"remark" withDefaultValue:@""];

    }else{
        [postValue setObject:orderID forKey:@"dataid" withDefaultValue:@""];
        [postValue setObject:eventID forKey:@"aid" withDefaultValue:@""];
        [postValue setObject:content forKey:@"content" withDefaultValue:@""];

    }
    [postValue setObject:[NSString stringWithFormat:@"%d",status]  forKey:@"status" withDefaultValue:@""];
    if (isRealOrder) {
        [postValue setObject:price forKey:@"price" withDefaultValue:@""];
        [postValue setObject:chargeType forKey:@"chargetype" withDefaultValue:@"1"];
    }
    
    //    [postValue setObject:[GloableEngineService sharedInstance].nickName forKey:@"name" withDefaultValue:@""];
    //    [postValue setObject:[GloableEngineService sharedInstance].bduss forKey:@"bduss" withDefaultValue:@""];
    // 异步获取数据
    NSString *urlSuffix = nil;
    if (isRealOrder) {
        urlSuffix =  kRCOrderUpdatePrefix;
    }else{
        urlSuffix = kRCActivityUpdatePrefix;
    }
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    
    KFLog(@"request url %@",url);
    return [[IDataProvider sharedInstance] asyncPostData:url postValues:postValue postDataList:nil userInfo:nil withDataParseClass:[RCBaseServerDataModel class] withDataDelegate:delegate];
}


//获取	活动详情
-(int64_t)requestActivityDetailInfo:(NSString *)aid
                       withDelegate:(id<IManagerDelegate>)delegate
{
    if ([NSString stringIsNullOrEmpty:aid]) {
        return kInvalidRequestId;
    }
    NSString *shopBduss = [[GloableEngineService sharedInstance] shopBduss];
    
    NSString *urlSuffix = nil;
    urlSuffix =  [NSString stringWithFormat:kActiveInfoDetailPrefix,shopBduss,aid];
  
    
    
    
    NSString *url = [RequestUtlity getFormattedUrl:urlSuffix];
    KFLog(@"request url %@",url);
    //    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObject:@"MerchantDetailJson"] forKeys:[NSArray arrayWithObject:@"FakeJson"]];
    return [[IDataProvider sharedInstance] asyncFetchDataWithUserInfo:url
                                                             userInfo:nil
                                                      withCachePolicy:IDataCachePolicyLocalFileAndNetwork
                                                   withDataParseClass:[RCActivityDetailInfoModel class]
                                                     withDataDelegate:delegate];
}
@end
